.PHONY: build clean help deps fmt lint test run

# Build variables
BINARY_NAME := goyolo-service
OUTPUT_DIR := bin
GO := go
GOOS := linux
GOARCH := amd64
CGO_ENABLED := 0

# Default target
.DEFAULT_GOAL := help

help:
	@echo "YOLOv8 OpenVINO Go Service Build Targets:"
	@echo "  make deps       - Download dependencies"
	@echo "  make build      - Build the service"
	@echo "  make clean      - Clean build artifacts"
	@echo "  make rebuild    - Clean and build"
	@echo "  make fmt        - Format code"
	@echo "  make lint       - Run linter"
	@echo "  make run        - Run the service"
	@echo "  make help       - Show this help message"

deps:
	@echo "Downloading dependencies..."
	$(GO) mod download
	$(GO) mod tidy

build: deps
	@echo "Building $(BINARY_NAME)..."
	@mkdir -p $(OUTPUT_DIR)
	CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO) build \
		-o $(OUTPUT_DIR)/$(BINARY_NAME) \
		-ldflags="-s -w" \
		.
	@echo "Build completed. Binary: $(OUTPUT_DIR)/$(BINARY_NAME)"

clean:
	@echo "Cleaning build artifacts..."
	@rm -rf $(OUTPUT_DIR)
	@$(GO) clean
	@echo "Clean completed."

rebuild: clean build

fmt:
	@echo "Formatting code..."
	$(GO) fmt ./...

lint:
	@echo "Running linter..."
	@if command -v golangci-lint &> /dev/null; then \
		golangci-lint run ./...; \
	else \
		echo "golangci-lint not installed. Skipping."; \
	fi

run: build
	@echo "Running service..."
	@./$(OUTPUT_DIR)/$(BINARY_NAME)

# Development build with debug info
dev-build: deps
	@echo "Building development version..."
	@mkdir -p $(OUTPUT_DIR)
	$(GO) build \
		-o $(OUTPUT_DIR)/$(BINARY_NAME)-dev \
		.
	@echo "Development build completed. Binary: $(OUTPUT_DIR)/$(BINARY_NAME)-dev"

